


let Command = require('./command');

// 删除chain. 删除哪一个chain????
class RemoveChainCommand extends  Command{
    constructor(chain){
        super();

        this.name = 'Remove Chain Node';
        this.type = 'RemoveChain';
        // this.chain = chain;

        // 还需要保存chain上的信息
        // 1. selNode 的顺序
        // 2. bkps
        this._model = chain.getModel(false);

        // // 依赖的对象
        // this.depens.push({
        //     name:'chain',
        //     obj:this.chain,
        // });

        this.setObj('chain',chain);

        this._lstAffect = [];
    }

    execute(){
        let chain = this.getObj('chain');
        this._lstAffect = this.getDepenItems(chain);

        let gameMap = G.gameMap;
        gameMap.removeChain(chain);

        this.cleanAffectLst(this._lstAffect);
    }

    undo(){
        let mapScene = G.gameMap;
        let chain;
        if(mapScene.lstChain.length === 1 &&
           mapScene.curChain.lstSel.length < 1){
            // 不新添加chain.  只需重置数据
            chain = mapScene.curChain;
            chain.parseData(this._model);
        }else{
            chain = mapScene._createChain();
            chain.parseData(this._model);
        }
        this.setObj('chain',chain);

        // 更新
        this.setAffectLst(this._lstAffect,chain);
    }
}


module.exports = RemoveChainCommand;
